<%-- 
    Document   : index
    Created on : Jan 26, 2010, 4:14:03 PM
    Author     : Puja, Szymanski
--%>

<%@page import="fr.ensisa.pujaszymanski.*, java.util.*" session="true" contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<%
    Forum f;

    if(this.getServletContext().getAttribute("forum") == null) {
	f = new Forum();
	this.getServletContext().setAttribute("forum", f);
    }
    else
	f = (Forum) this.getServletContext().getAttribute("forum");

    String userName = ((String) session.getAttribute("userName") != null)  ? (String) session.getAttribute("userName") : "";
%>

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>MiniForum - Puja, Szymanski</title>
    </head>
    <body>
	<form action="login" method="post">
	    Internaute : <input type="text" name="userName" value="<%=userName %>" />
	    <input type="submit" name="buttonLogin" value="Login" />
	</form>

        <h1>MiniForum - Puja, Szymanski</h1>
	<hr />
	<h2>Sujets - [ <a href="new_topic.jsp"> Nouveau Sujet</a> ]</h2>
	<%
	    if(f.isEmpty())
		out.write("Aucun topics.");
	    else {
		Iterator<Topic> it = f.iterator();

		out.write("<ul>");

		while(it.hasNext()) {
		    Topic t = it.next();
		    out.write("<li><a href=\"topic.jsp?idTopic=" + t.getIdTopic() + "\">" + t.getTitle() + "</a></li>");
		}

		out.write("</ul>");
	    }
	%>
    </body>
</html>
